package com.zhoujian.Prototype.shallowCopy;

import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
class PlayList2clone implements Serializable,Cloneable{
    private Long id;
    private String name;
    private List<Song> songs = new ArrayList<>();

    public PlayList2clone(){

    }

    public void add(Song song){
        songs.add(song);
    }

    public PlayList2clone(PlayList2clone sourcePlayList) {
        this.id = sourcePlayList.getId();
        this.name = sourcePlayList.getName();
        this.songs = sourcePlayList.getSongs();
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public static void main(String[] args) throws CloneNotSupportedException {
        PlayList2clone playList =new PlayList2clone();
        playList.setId(1L);
        playList.setName("杰伦");
        playList.add(new Song("稻香","周杰伦"));
        playList.add(new Song("稻香","周杰伦"));
        playList.add(new Song("稻香","周杰伦"));

        PlayList2clone favouriteList = (PlayList2clone) playList.clone();
        System.out.println(favouriteList);
    }

}